# -*- coding: utf-8 -*-
# @Time    : 2022/4/2 16:14
# @Author  : zyw
# @Email   : panda_kings@163.com
# @File    : users.py
import datetime

# from common.models.news import NewsInfo
from common.models import db


class User(db.Model):
    """用户表"""
    __tablename__ = 'tb_user'
    uid = db.Column(db.Integer, primary_key=True,autoincrement=True,doc="用户id")
    mobile = db.Column(db.String(16),unique=True, doc="手机号")
    gender = db.Column(db.Integer,default=1, doc="性别")
    password = db.Column(db.String(256), doc="密码")
    account = db.Column(db.String(32), doc="账号")
    email = db.Column(db.String(64), doc="邮箱")
    status = db.Column(db.Integer, default=1, doc=" 状态，是否可用")
    nick_name = db.Column(db.String(20), unique=True,doc="昵称")
    profile_photo = db.Column(db.String(200), doc="头像")
    last_login = db.Column(db.DateTime,doc="最后登录时间",default=datetime.datetime.now())
    is_media = db.Column(db.Boolean, default=True,doc="是否是自媒体")
    is_verified = db.Column(db.Boolean, default=False,doc="是否实名认证")
    introduction = db.Column(db.String(20), doc="简介")
    certificate = db.Column(db.String(20), doc="认证")
    article_count = db.Column(db.Integer,default=0,doc="发帖数")
    following_count = db.Column(db.Integer,default=0,doc="关注的人数")
    fans_count = db.Column(db.Integer,default=0,doc="被关注的人数（粉丝数)")
    like_count = db.Column(db.Integer,default=0,doc="累计点赞人数")
    read_count = db.Column(db.Integer,default=0,doc="累计阅读人数")


# 2.用户关注关系表
class Relation(db.Model):
    user_id = db.Column(db.Integer, db.ForeignKey("tb_user.uid"), primary_key=True,doc="关注的人")
    fans_id = db.Column(db.Integer, db.ForeignKey("tb_user.uid"), primary_key=True,doc="粉丝")
    relation = db.Column( db.Boolean, doc='状态(1,关注;0, 取消)')
    create_time = db.Column(db.DateTime, default=datetime.datetime.now(), doc='创建时间')
    update_time = db.Column(db.DateTime, default=datetime.datetime.now(), onupdate=datetime.datetime.now(), doc='更新时间')
    user = db.relationship('User', foreign_keys=user_id)
    follower = db.relationship('User', foreign_keys=fans_id)


class OauthUser(db.Model):
    """
    第三方登录表(微信登录/qq登录/微博登录)
    """
    __tablename__ = 'oauth_user_tb'
    id = db.Column(db.Integer, primary_key=True, doc='oauth_user id')
    image = db.Column(db.String(64), doc='头像')
    uid = db.Column(db.String(512), doc='第三方登录的id')
    user = db.Column(db.Integer, db.ForeignKey("tb_user.uid", ondelete="CASCADE"))
    oauth_type = db.Column(db.String(128), doc='第三方登录类型')




